<?php
ini_set("error_reporting","E_ALL & ~E_NOTICE");
$user=$_POST["user"];
$modid=$_POST["modid"];
$modname=$_POST["modname"];
$modimg=$_POST["modimg"];
$modjson=$_POST["modjson"];
$customWidth=$_POST["customWidth"];
$customHeight=$_POST["customHeight"];

if ($user!="" and $modid!="" and $modname!="" and $modimg!="" and $modjson!="" and $customWidth!="" and $customHeight!="") {
	$filename='../../user/'.$user.'.json';
	$json_string = file_get_contents($filename);
	$data = json_decode($json_string, true);
	$pd="N";
    if (file_exists($filename)) {//文件存在
        if (array_key_exists("mod",$data)) {//mod配置是否已存在
            $Count = count($data['mod']);//查询条目数
            for ($i=0; $i < $Count; $i++) {
                $modids = $data['mod'][$i]['modid'];
                if ($modid==$modids) {
                    $data['mod'][$i]["modid"]=$modid;
					$data['mod'][$i]["modname"]=$modname;
                    $data['mod'][$i]["modimg"]=$modimg;
					$data['mod'][$i]["modjson"]=$modjson;
					$data['mod'][$i]["customWidth"]=$customWidth;
					$data['mod'][$i]["customHeight"]=$customHeight;
                    $data['mod'][$i]["zt"]=1;
                    $pd="Y";//数据已存在
                    $datas['status']="YES";
                    $datas['message']="恭喜您，配置模板更新成功！";
                    echo json_encode($datas);
                }
            }

            if ($pd=="N") {
                $datas['status']="NO";
                $datas['message']="[0]配置文件更新出错，配置模板不存在！";
                echo json_encode($datas);
            }
            $json = json_encode($data);
            file_put_contents($filename, $json);
            
        } else {//mod不存在，直接写0
            $datas['status']="NO";
            $datas['message']="[1]配置文件更新出错，更新配置模板失败！";
            echo json_encode($datas);
        }
    } else {//文件不存在
        $datas['status']="NO";
        $datas['message']="[2]配置文件更新出错，更新配置模板失败！";
        echo json_encode($datas);
    }
    
} else {
    $datas['status']="NO";
    $datas['message']="配置模板内容读取错误，更新配置模板失败！";
    echo json_encode($datas);
}
?>